package hapi.log;

import haxe.PosInfos;

interface LogDecorator {
	public function decorate( message:Dynamic, inf : PosInfos ):String;
}

class DetailedLogDecorator implements LogDecorator {
	
	public function new(){}
	
	public function decorate(message:Dynamic, inf : PosInfos) {
		return posInfosToString(inf)+" "+Std.string(message);
	}
	
	inline function posInfosToString(inf : PosInfos) {
		var buf = new StringBuf();
		var level = Std.string(inf.customParams[0]);
		if ( level == null || level == "" || level == "null" ) level = "debug";
		buf.add(level);
		buf.add("> ");
		if( inf.customParams[1] != "plain" ) {
		buf.add(inf.lineNumber + ":" + inf.className + "." + inf.methodName);
			if(inf.customParams != null && inf.customParams.length > 0)
				buf.add("[" + Std.string(inf.customParams) + "]");
		}
		return buf.toString();
	}
}

class NoLogDecorator implements LogDecorator {
	
	public function new() { }
	
	public function decorate(message:Dynamic, inf : PosInfos) {
		return Std.string(message);
	}
}